﻿package mortal.game.view.guildNew.shop
{
    import Message.DB.Tables.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.signUp.sevenDayLogin.item.*;
    import mortal.mvc.core.*;

    public class GuildNewShopPanel extends GSprite implements GuildNewPanelI
    {
        protected var _bg:ScaleBitmap;
        protected var _list:GTileList;
        protected var _donateBg:GBitmap;
        protected var _line:ScaleBitmap;
        protected var _honorPic:GBitmap;
        protected var _bTip:GTextFiled;
        protected var _btip2:GTextFiled;
        protected var _hornorNum:BitmapNumberText;
        protected var _pageSelecter:PageSelecter;
        private var _hideTipArea:HideAreaSp;
        private const showAmount:int = 12;

        public function GuildNewShopPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.bg(0, 0, 748, 475, this, ImagesConst.PanelBg);
            this._list = UIFactory.tileList(7, 8, 750, 428, this);
            this._list.direction = GBoxDirection.VERTICAL;
            this._list.verticalGap = 1;
            this._list.horizontalGap = 2;
            this._list.rowHeight = 107;
            this._list.columnWidth = 245;
            this._list.columnCount = 3;
            this._list.rowCount = 4;
            this._list.width = 750;
            this._list.setStyle("cellRenderer", GuildNewShopCell);
            this._donateBg = UIFactory.gBitmap(ImagesConst.GuildNewHornor, -3, 442, this);
            this._line = UIFactory.bg(2, 442, 755, 1, this, ImagesConst.SplitLine);
            this._honorPic = UIFactory.gBitmap(ImagesConst.honor, 148, 445, this);
            this._bTip = UIFactory.gTextField("" + Language.getString(71607), 470, 448, 200, 20, this, GlobalStyle.textFormatPutong.setColor(16777215));
            this._btip2 = UIFactory.gTextField("" + Language.getString(71608), 660, 448, 100, 20, this, GlobalStyle.textFormatLv);
            this._hornorNum = UIFactory.bitmapNumberText(81, 448, "WizardNum.png", 13, 17, 0, this, 13, 0);
            this._hornorNum.text = "10000";
            this._pageSelecter = UIFactory.pageSelecter(323, 447, this, PageSelecter.CompleteMode);
            this._pageSelecter.setbgStlye(ImagesConst.ComboBg, GlobalStyle.textFormatBai.center());
            this._pageSelecter.maxPage = 1;
            this._pageSelecter.pageTextBoxSize = 36;
            this._pageSelecter.configEventListener(Event.CHANGE, this.onPageChange);
            this._hideTipArea = UIFactory.getUICompoment(HideAreaSp, 10, 441, this);
            this._hideTipArea.drawRec(150, 30, 0.01);
            this._hideTipArea.toolTipData = "" + Language.getString(71609);
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildShopGetItem));
            this.updateContribution();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bg = null;
            this._list = null;
            this._donateBg = null;
            this._line = null;
            this._honorPic = null;
            this._bTip = null;
            this._btip2 = null;
            this._hornorNum = null;
            this._pageSelecter = null;
            this._hideTipArea = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            this._list.dataProvider = this.getDataProvider();
            this._list.drawNow();
            return;
        }// end function

        public function update() : void
        {
            this._list.dataProvider = this.getDataProvider();
            this._list.drawNow();
            return;
        }// end function

        public function updateContribution(param1:Object = null) : void
        {
            var _loc_2:* = Cache.instance.guild.selfGuildInfo.selfInfo.contribution;
            this._hornorNum.text = _loc_2.toString();
            if (_loc_2 > 10000)
            {
                this._honorPic.x = this._hornorNum.x + this._hornorNum.width + 8;
            }
            else
            {
                this._honorPic.x = 148;
            }
            return;
        }// end function

        private function getDataProvider() : DataProvider
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:TGuildShopSell = null;
            var _loc_6:Object = null;
            var _loc_7:int = 0;
            var _loc_1:* = new DataProvider();
            var _loc_2:* = Cache.instance.guild.selfGuildInfo.shop.itemsArr;
            if (_loc_2 == null)
            {
                return _loc_1;
            }
            this._pageSelecter.maxPage = Math.ceil(_loc_2.length / this.showAmount);
            if (_loc_2)
            {
                _loc_3 = this.showAmount + (this._pageSelecter.currentPage - 1) * this.showAmount;
                _loc_4 = (this._pageSelecter.currentPage - 1) * this.showAmount;
                _loc_7 = _loc_4;
                while (_loc_7 < _loc_3)
                {
                    
                    if (_loc_2[_loc_7])
                    {
                        _loc_5 = GuildShopConfig.instance.getGuildShopSellByCode(_loc_2[_loc_7].itemCode);
                        if (_loc_5)
                        {
                            _loc_6 = {sguildShopItem:_loc_2[_loc_7], tGuildShopItem:_loc_5};
                            _loc_1.addItem(_loc_6);
                        }
                    }
                    _loc_7++;
                }
            }
            return _loc_1;
        }// end function

    }
}
